package org.grayrabbit.cms.content.base;

import java.util.HashMap;
import java.util.Map;


/**
 *		Mission.java
 *		@Author      hasau   
 *		@CreateTime  2012-2-8  上午9:17:53	
 **/
public  class BaseMission {
	public static final int THREAD_MAX_NUM = 5; 
	
	private static Map<String,CountDto> MAP= new HashMap<String,CountDto>();
	
	/**当前线程数*/
	public  static void updateCurrentNum(int i,String key){
		synchronized(MAP){
			CountDto dto = (CountDto)(MAP.get(key));
			dto.setThreadCurrentNum(dto.getThreadCurrentNum()+i) ;
			MAP.put(key,dto);
		}
	}
	
	/**成功完成的XML文件数量  已经操作过的  成功的 数量*/
	public  static void countDoneNum(String key,int i){		
		if(i <1) return;
		synchronized(MAP){			
			CountDto dto = (CountDto)(MAP.get(key)); 
			dto.setHaveDoneNum( dto.getHaveDoneNum() +i);
			MAP.put(key,dto);
		}
	}
	
	/**剩余的任务数*/
	public  static void countMissionLeftNum(String key){
		synchronized(MAP){	
			CountDto dto = (CountDto)(MAP.get(key));
			dto.setMissionLeftNum(dto.getMissionLeftNum()-1);
			MAP.put(key,dto);
		}
	}
	/**运行过的线程总数  已经操作过的数量 不论成功与否 都计数*/
	public  static void countItemTotalNum(String key){
		synchronized(MAP){	
			CountDto dto = (CountDto)(MAP.get(key));
			dto.setItemTotalNum(dto.getItemTotalNum()+1);
			MAP.put(key,dto);
		}
	}
	
	public  static void countExistOrErrorNum(String key,int i){
		if(i <1) return;
		synchronized(MAP){	
			CountDto dto = (CountDto)(MAP.get(key)); 
			dto.setExistOrErrorNum( dto.getExistOrErrorNum() +i);
			MAP.put(key,dto);
		}
	}
	
	public  static void addMapItem(String key,CountDto dto){
		synchronized(MAP){	
			MAP.put(key,dto);
		}
	}
	public  static CountDto getMapItem(String key){
		synchronized(MAP){	
			Object obj = MAP.get(key);
			if(obj == null) return null;
			return (CountDto)obj;
		}
	}
	
	public static void removeItem(String key){
		synchronized(MAP){	
			MAP.remove(key);
		}
	}
	
}
